{% extends "base_portadmin.html" %}

{% block object-tools %}
	<ul class="object-tools">
		{#	<a class="reloadlink" herf="#" onclick="JrcLoadCsts(gPageNr); return false;">Reload</a> #}
		<li>
			<a class="addlink" href="/portadmin/cst/add/">Add CST</a>
		</li>
    </ul>
{% endblock %}

{% block mainheading %}{{ block.super }} \ Comb Signal Time{% endblock %}

{% block content %}

		<div id="ParametersLoader" style="display: none;"><img src="{{ MEDIA_URL }}/images/ajaxloading.gif" alt="Loading..." /></div>

		<div>
		<table cellspacing="0">

			<thead>
			<tr>
				<th class="action-checkbox-column"></th><th>
				PK
				</th><th nowrap>Status id
				</th><th>
				Name
				</th><th>
				Fees
				</th><th>
				Session
				</th><th nowrap>
				Market direction 1
				</th><th nowrap>
				Market direction 2
				</th><th>
				Timelevel
				</th><th nowrap>
				Created at
				</th><th>
				Actions
				</th>
			</tr>

			<tr>
			<th class="action-checkbox-column"></th><th>
			</th><th>
			<select id="StatusId" name="status_id" onchange="JrcLoadCsts(gPageNr);">
				<option value="0">Status id</option>
				<option value="1">tested</option>
				<option value="2">implemented</option>
				<option value="3">sorted out</option>
				<option value="4">deleted</option>
			</select>
			</th><th>
			</th><th>
			</th><th>
			</th><th>
			<select id="MarketDirection1" name="market_direction_1" onchange="JrcLoadCsts(gPageNr);">
				<option value="">Market direction 1</option>
				{% for p in parameters %}
					<option value="{{ p.pk }}">{{ p.market_name }} {{ p.direction_name }}</option>
				{% endfor %}
			</select>
			</th><th>
			<select id="MarketDirection2" name="market_direction_2" onchange="JrcLoadCsts(gPageNr);">
				<option value="">Market direction 2</option>
				{% for p in parameters %}
					<option value="{{ p.pk }}">{{ p.market_name }} {{ p.direction_name }}</option>
				{% endfor %}
			</select>
			</th><th>
			<select id="TimeLevelId" name="timelevel_id" onchange="JrcLoadCsts(gPageNr);">
				<option value="">Timelevel</option>
				{% for t in timelevels %}
					<option value="{{ t.pk }}">{{ t.name }}</option>
				{% endfor %}
			</select>
			</th><th>
			</th><th>
			</th>
			</tr>
			</thead>

		<tbody id="ParametersTbody">
		</tbody>

	</table>
	</div>


<script type="text/javascript">

	var gPageNr = {{ page }};
	var gIsOperationLoaded = true;

	function JrcLoadCsts(page)
	{
		if( gIsOperationLoaded )
		{
			gIsOperationLoaded = false;
			jQuery("#ParametersLoader").show();
			
			jQuery.ajax({
				url: "/portadmin/" + page + "/getcstsnew/"
				//, data: "system_id=" + systemId + "&market_id=" + marketId
				, data: "status_id=" + jQuery("#StatusId").val() + "&timelevel_id=" + jQuery("#TimeLevelId").val() + "&market_direction_1=" + jQuery("#MarketDirection1").val() + "&market_direction_2=" + jQuery("#MarketDirection2").val()
				, success: function(data){ OnJrcCstsLoaded(data); }
				, error: function(){ OnJrcCstsFailed(); }
				, cache: false
			});
		}
	}

	function OnJrcCstsLoaded(data)
	{
		gIsOperationLoaded = true;
		jQuery("#ParametersLoader").hide();
		jQuery("#ParametersTbody").html(data);
	}

	function OnJrcCstsFailed()
	{
		gIsOperationLoaded = true;
		jQuery("#ParametersLoader").hide();
		jQuery("#ParametersTbody").html("<tr><td colspan='7'>Error loading data!</td></tr>");
	}

</script>

{% endblock %}


{% block js_on_load %}

	{{ block.super }}

	// Loading initial parameters
	JrcLoadCsts(gPageNr);

{% endblock %}
